package SEDay07;

/*#### #### 案例需求

            ​	已知一个数组 arr = {19, 28, 37, 46, 50}; 用程序实现把数组中的元素值交换，
            ​        交换后的数组 arr = {50, 46, 37, 28, 19}; 并在控制台输出交换后的数组元素。*/

import java.util.Scanner;

public class Text05 {
    public static void main(String[] args) {
        int[] arr = {19, 28, 37, 46, 50};
        int[] changeArr = change(arr);
        System.out.print("交换后的数组为：[");
        for (int i = 0; i < changeArr.length; i++) {
            if (i == changeArr.length - 1) {
                System.out.println(changeArr[i] + "]");
            } else {
                System.out.print(changeArr[i] + ",");
            }
        }
    }

    public static int[] change(int[] arr) {
        int temp = 0;
        for (int i = 0; i < arr.length / 2; i++) {
            temp = arr[i];
            arr[i] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = temp;
        }
        return arr;
    }
}
